### https://www.kubecube.io/docs/installation-guide/install-on-k8s/install-pivot-by-helm/

KUBECUBE_VERSION=v1.8
curl -s https://kubecube.nos-eastchina1.126.net/kubecube-chart/${KUBECUBE_VERSION}/kubecube-chart.tar.gz | tar -xz

IPADDR=""

function pivot_values() {
  
cat > pivot-values.yaml <<EOF
# pivot-value.yaml

global:
  # 管控集群的 Node IP，用来暴露 KubeCube 的 NodePort service
  nodeIP: ${IPADDR}

  dependencesEnable:
    ingressController: "true" # set "true" to deploy if ingress is not already in cluster.
    localPathStorage: "true"
    metricServer: "true"

  localKubeConfig: $(cat /root/.kube/config | base64 -w 0) # local cluster kubeconfig base64
  pivotKubeConfig: $(cat /root/.kube/config | base64 -w 0) # pivot cluster kubeconfig base64
  
  ## 如果要启动日志功能，请将以下值设置为 "enabled"
  hotPlugEnable:
    pivot:
      logseer: "disabled"
      logagent: "disabled"
      elasticsearch: "disabled"

warden:
  containers:
    warden:
      args:
        cluster: "pivot-cluster"  # set current cluster name
EOF
}

pivot_values

INSTALL_NAMESPACE="kubecube-system"


/usr/local/bin/helm install kubecube -n ${INSTALL_NAMESPACE} --create-namespace ./kubecube-chart -f ./pivot-values.yaml
